#include <iostream>
//#include "gameboard.h"
class Best
{
    public:
	char color;
    int row;
    int column;
    
    Best()
    {
        
        row = 0;
        column = 0;
    }
   
    void get_color(char c);
    int count_num_moves(Gameboard board);
	void think( Gameboard board,int level);
    int chooseMove( int depth, Gameboard board, short row1, short column1,int level);
    void evaluate();
	bool no_move_available(Gameboard board);
};

void Best:: get_color(char c)
{
	color=c;
}

int Best:: count_num_moves(Gameboard board)
{
    int p = 0;
    for(int i=1; i<10; i++)
    {
        for(int j=1; j<10; j++)
        {
            if(board.board[i][j] == '*')
            {
                p++;
               
            }
        }
    }
    return p;
}

void Best:: think(Gameboard board,int level)
{
	int row1,column1;
	int newmovevalue;
	int bestmove;
	for(int i=0; i<10; i++)
        {
            for(int j=0; j<10; j++)
            {
                if(board.board[i][j] == '*')
                {

                    row1 = i;
                    column1 = j;
                    newmovevalue = chooseMove(2,board,row1,column1,level);
                    if(bestmove >= newmovevalue)
                    {
                        
                        bestmove = newmovevalue;
                        row = row1;
                        column = column1;
                    }
                }
            }
        }

}

int Best:: chooseMove( int depth, Gameboard board, int row1, int column1, int level)
{
	int bestoption;
	int color_count=0;
	int space_count=0;
	if(depth < level&&!no_move_available(board))
    {
        int d=depth+1;
		int bestoptionhigh=-1;
		int bestoptionlow=100;
		int l = row1;
        int j = column1;
		int newmover;
        board.move(l,j);
        board.showNextPos();

        for(int i=0; i<10; i++)
        {
            for(int j=0; j<10; j++)
            {
                if(board.board[i][j] == '*')
                {
                   newmover = chooseMove(d,board,i,j,level);
                    if((bestoptionhigh <= newmover) && ((depth)%2 == 0))
                    {
                        bestoption = newmover;
					}
                    if((bestoptionlow >= newmover) && ((depth)%2 != 0))
                    {
                        bestoption = newmover;
                    }

                }
               
            }
        }
		return bestoption;
	}
	else
	{
		if(depth==level&&!no_move_available(board)&&!gameover(board))
		{
			bestoption = count_num_moves(board);
			return bestoption;
		}
		if(no_move_available(board)&&!gameover)
		{
			return 100;
		}
		if(gameover(board))
		{
			for(int i=0; i<10; i++)
			{
				for(int j=0; j<10; j++)
				{
					if(board.board[i][j] == color)
					{ 
						color_count++;
					}
					if(board.board[i][j] =='_')
					{
						space_count++;
					}
				}
			}
			if(64-(color_count+space_count)<color_count)
			{
				return -1;
			}
			else
			{
				return 100;
			}
		}
	}


}

int Best:: count_num_moves(Gameboard board)
{
    int p = 0;
    for(int i=1; i<10; i++)
    {
        for(int j=1; j<10; j++)
        {
            if(board.board[i][j] == '*')
            {
                p++;
               
            }
        }
    }
    return p;
}
bool Best::no_move_available(Gameboard board)
{
	if(count_num_moves(board)==0)
		return true;
	return false;
}

bool Best:: gameover(Gameboard board)
{
	int numEmpty=0;
	int p=0;
	for(int i=0; i<10; i++)
	{
		for(int j=0; j<10; j++)
		{
			if(board[i][j] == '_')
			{ 
				numEmpty++;
			}
			if(board[i][j] == '*')
			{ 
				p++;
			}
		}
	}
	if((p == 0 )&& numEmpty==0)
		return true;
	return false;
}





